﻿using SinBiota.Model.Entities;
using SinBiota.Model.Persistence.NHibernateMappings;

namespace Sinbiota.Model.Persistence.NHibernateMappings
{
    public class UserMapping : BaseEntityMapping<User>
    {
        public UserMapping()
        {
            Map(u => u.Name).Not.Nullable().Length(128);
            Map(u => u.Address).Length(1000);
            Map(u => u.PhoneNumber).Length(50);
            Map(u => u.FaxNumber).Length(30);
            Map(u => u.Username).Not.Nullable().Length(50);
            Map(u => u.Password).Not.Nullable().Length(50);
            Map(u => u.PasswordSalt).Not.Nullable().Length(50);
            Map(u => u.Email).Not.Nullable().Length(128);
            Map(u => u.Comment).Nullable().Length(MAXCHAR);
            Map(u => u.Note).Nullable().Length(MAXCHAR);
            Map(u => u.PasswordQuestion).Nullable().Length(100);
            Map(u => u.FailedPasswordAttemptCount).Nullable();
            Map(u => u.PasswordAnswer).Nullable().Length(100);
            Map(u => u.IsApproved).Not.Nullable();
            Map(u => u.IsLockedOut).Not.Nullable();
            Map(u => u.IsOnline).Not.Nullable();
            Map(u => u.CreationDate).Not.Nullable();
            Map(u => u.LastLoginDate).Not.Nullable();
            Map(u => u.LastActivityDate).Not.Nullable();
            Map(u => u.LastLockedOutDate).Not.Nullable();
            Map(u => u.LastPasswordChangedDate).Not.Nullable();
            Map(u => u.Role).Not.Nullable().Length(20); 
            HasManyToMany(r => r.MemberProjects).Table("UserToProject_Member").Cascade.SaveUpdate();
            HasManyToMany(r => r.CoordinatorProjects).Table("UserToProject_Coordinator").Cascade.SaveUpdate();

        }
    }
}
